<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>S110_nRF51822/Source/ble/ble_conn_params.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css" />
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="alias.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="alias.js"></script>

<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>


<script type="text/javascript">
  jQuery(document).ready(function () {
    if(gref){ // Number all _img and _table classes
      gref();
    }
  });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->

<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">nRF51822 BLE SDK
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('ble__conn__params_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">S110_nRF51822/Source/ble/ble_conn_params.c</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.</span>
<a name="l00002"></a>00002 <span class="comment"> *</span>
<a name="l00003"></a>00003 <span class="comment"> * The information contained herein is property of Nordic Semiconductor ASA.</span>
<a name="l00004"></a>00004 <span class="comment"> * Terms and conditions of usage are described in detail in NORDIC</span>
<a name="l00005"></a>00005 <span class="comment"> * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> * Licensees are granted free, non-transferable use of the information. NO</span>
<a name="l00008"></a>00008 <span class="comment"> * WARRANTY of ANY KIND is provided. This heading must NOT be removed from</span>
<a name="l00009"></a>00009 <span class="comment"> * the file.</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * $LastChangedRevision$</span>
<a name="l00012"></a>00012 <span class="comment"> */</span>
<a name="l00013"></a>00013 
<a name="l00014"></a>00014 <span class="preprocessor">#include &quot;<a class="code" href="ble__conn__params_8h.html">ble_conn_params.h</a>&quot;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &quot;ble_hci.h&quot;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &quot;<a class="code" href="app__timer_8h.html">app_timer.h</a>&quot;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &quot;<a class="code" href="ble__srv__common_8h.html">ble_srv_common.h</a>&quot;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &quot;<a class="code" href="ble__sdk__util_8h.html">ble_sdk_util.h</a>&quot;</span>
<a name="l00020"></a>00020 
<a name="l00021"></a>00021 
<a name="l00022"></a>00022 <span class="keyword">static</span> <a class="code" href="structble__conn__params__init__t.html" title="Connection Parameters Module init structure. This contains all options and data needed for initializa...">ble_conn_params_init_t</a> s_conn_params_config;     
<a name="l00023"></a>00023 <span class="keyword">static</span> <a class="code" href="structble__gap__conn__params__t.html" title="GAP connection parameters.">ble_gap_conn_params_t</a>  s_preferred_conn_params;  
<a name="l00024"></a>00024 <span class="keyword">static</span> uint8_t                s_update_count;           
<a name="l00025"></a>00025 <span class="keyword">static</span> uint16_t               <a class="code" href="group__ble__sdk__app__hrs__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a>;            
<a name="l00026"></a>00026 <span class="keyword">static</span> <a class="code" href="structble__gap__conn__params__t.html" title="GAP connection parameters.">ble_gap_conn_params_t</a>  s_current_conn_params;    
<a name="l00029"></a>00029 <span class="keyword">static</span> <span class="keywordtype">bool</span> is_conn_params_ok(<a class="code" href="structble__gap__conn__params__t.html" title="GAP connection parameters.">ble_gap_conn_params_t</a> * p_conn_params)
<a name="l00030"></a>00030 {
<a name="l00031"></a>00031     <span class="comment">// Check if interval is within the acceptable range.</span>
<a name="l00032"></a>00032     <span class="comment">// NOTE: Using max_conn_interval in the received event data because this contains</span>
<a name="l00033"></a>00033     <span class="comment">//       the client&#39;s connection interval.</span>
<a name="l00034"></a>00034     <span class="keywordflow">if</span> (
<a name="l00035"></a>00035         (p_conn_params-&gt;<a class="code" href="structble__gap__conn__params__t.html#a0aec1884f340406a5194b772da017d7b">max_conn_interval</a> &gt;= s_preferred_conn_params.<a class="code" href="structble__gap__conn__params__t.html#ac927a642ee2203f875fcce1eabb5fa64">min_conn_interval</a>)
<a name="l00036"></a>00036         &amp;&amp; 
<a name="l00037"></a>00037         (p_conn_params-&gt;<a class="code" href="structble__gap__conn__params__t.html#a0aec1884f340406a5194b772da017d7b">max_conn_interval</a> &lt;= s_preferred_conn_params.<a class="code" href="structble__gap__conn__params__t.html#a0aec1884f340406a5194b772da017d7b">max_conn_interval</a>)
<a name="l00038"></a>00038     )
<a name="l00039"></a>00039     {
<a name="l00040"></a>00040         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00041"></a>00041     }
<a name="l00042"></a>00042     <span class="keywordflow">else</span>
<a name="l00043"></a>00043     {
<a name="l00044"></a>00044         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00045"></a>00045     }
<a name="l00046"></a>00046 }
<a name="l00047"></a>00047 
<a name="l00048"></a>00048 
<a name="l00049"></a>00049 <span class="keyword">static</span> <span class="keywordtype">void</span> update_timeout_handler(app_timer_id_t timer_id)
<a name="l00050"></a>00050 {
<a name="l00051"></a>00051     <span class="comment">// Check if we have reached the maximum number of attempts</span>
<a name="l00052"></a>00052     s_update_count++;
<a name="l00053"></a>00053     <span class="keywordflow">if</span> (s_update_count &lt;= s_conn_params_config.<a class="code" href="structble__conn__params__init__t.html#ab3c0944561623d4a8da622b18867aafb">max_conn_params_update_count</a>)
<a name="l00054"></a>00054     {
<a name="l00055"></a>00055         <span class="comment">// Check the current connection parameters</span>
<a name="l00056"></a>00056         <span class="keywordflow">if</span> (!is_conn_params_ok(&amp;s_current_conn_params))
<a name="l00057"></a>00057         {
<a name="l00058"></a>00058             uint32_t err_code;
<a name="l00059"></a>00059             
<a name="l00060"></a>00060             <span class="comment">// Parameters are not ok, send connection parameters update request.</span>
<a name="l00061"></a>00061             err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga0f9c19bde4ab1e2f8a3a697908c91368" title="Update connection parameters.">ble_gap_conn_param_update</a>(<a class="code" href="group__ble__sdk__app__hrs__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a>, &amp;s_preferred_conn_params);
<a name="l00062"></a>00062             <span class="keywordflow">if</span> ((err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>) &amp;&amp; (s_conn_params_config.<a class="code" href="structble__conn__params__init__t.html#a893a7b5845beb42d9e5b650fd012f7f1">error_handler</a> != NULL))
<a name="l00063"></a>00063             {
<a name="l00064"></a>00064                 s_conn_params_config.<a class="code" href="structble__conn__params__init__t.html#a893a7b5845beb42d9e5b650fd012f7f1">error_handler</a>(err_code);
<a name="l00065"></a>00065             }
<a name="l00066"></a>00066         }
<a name="l00067"></a>00067     }
<a name="l00068"></a>00068     <span class="keywordflow">else</span>
<a name="l00069"></a>00069     {
<a name="l00070"></a>00070         <span class="comment">// Negotiation failed, disconnect automatically if this has been configured</span>
<a name="l00071"></a>00071         <span class="keywordflow">if</span> (s_conn_params_config.<a class="code" href="structble__conn__params__init__t.html#a7a3f3aac03305ef8012ade05399b5449">disconnect_on_fail</a>)
<a name="l00072"></a>00072         {
<a name="l00073"></a>00073             uint32_t err_code;
<a name="l00074"></a>00074             
<a name="l00075"></a>00075             err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga1b72b0bedcc2ff560582527aee8e6416" title="Disconnect (GAP Link Termination).">ble_gap_disconnect</a>(<a class="code" href="group__ble__sdk__app__hrs__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a>, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE);
<a name="l00076"></a>00076             <span class="keywordflow">if</span> ((err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>) &amp;&amp; (s_conn_params_config.<a class="code" href="structble__conn__params__init__t.html#a893a7b5845beb42d9e5b650fd012f7f1">error_handler</a> != NULL))
<a name="l00077"></a>00077             {
<a name="l00078"></a>00078                 s_conn_params_config.<a class="code" href="structble__conn__params__init__t.html#a893a7b5845beb42d9e5b650fd012f7f1">error_handler</a>(err_code);
<a name="l00079"></a>00079             }
<a name="l00080"></a>00080         }
<a name="l00081"></a>00081         
<a name="l00082"></a>00082         <span class="comment">// Notify the application that the procedure has failed</span>
<a name="l00083"></a>00083         <span class="keywordflow">if</span> (s_conn_params_config.<a class="code" href="structble__conn__params__init__t.html#af6344191be6d1f66ec79d6086def25f1">evt_handler</a> != NULL)
<a name="l00084"></a>00084         {
<a name="l00085"></a>00085             <a class="code" href="structble__conn__params__evt__t.html" title="Connection Parameters Module event.">ble_conn_params_evt_t</a> evt;
<a name="l00086"></a>00086             
<a name="l00087"></a>00087             evt.<a class="code" href="structble__conn__params__evt__t.html#a43fc16c6c20c00363c03e968c21c08d7">evt_type</a> = <a class="code" href="group__ble__sdk__lib__conn__params.html#ggae819a1b14dbebf447254ec41f644ec42a693314f30d0f73380ae2701d1094179a">BLE_CONN_PARAMS_EVT_FAILED</a>;
<a name="l00088"></a>00088             s_conn_params_config.<a class="code" href="structble__conn__params__init__t.html#af6344191be6d1f66ec79d6086def25f1">evt_handler</a>(&amp;evt);
<a name="l00089"></a>00089         }
<a name="l00090"></a>00090     }
<a name="l00091"></a>00091 }
<a name="l00092"></a>00092 
<a name="l00093"></a>00093 
<a name="l00094"></a><a class="code" href="group__ble__sdk__lib__conn__params.html#gacd9789a0a4c90cfea2ba2656f6408080">00094</a> uint32_t <a class="code" href="group__ble__sdk__lib__conn__params.html#gacd9789a0a4c90cfea2ba2656f6408080" title="Initialize the Connection Parameters module.">ble_conn_params_init</a>(<span class="keyword">const</span> <a class="code" href="structble__conn__params__init__t.html" title="Connection Parameters Module init structure. This contains all options and data needed for initializa...">ble_conn_params_init_t</a> * p_init)
<a name="l00095"></a>00095 {
<a name="l00096"></a>00096     uint32_t err_code;
<a name="l00097"></a>00097     
<a name="l00098"></a>00098     s_conn_params_config = *p_init;
<a name="l00099"></a>00099     <span class="keywordflow">if</span> (p_init-&gt;<a class="code" href="structble__conn__params__init__t.html#ab211e40857ee8019c8fd5eabfcc12ce7">p_conn_params</a> != NULL)
<a name="l00100"></a>00100     {
<a name="l00101"></a>00101         s_preferred_conn_params = *p_init-&gt;<a class="code" href="structble__conn__params__init__t.html#ab211e40857ee8019c8fd5eabfcc12ce7">p_conn_params</a>;
<a name="l00102"></a>00102         
<a name="l00103"></a>00103         <span class="comment">// Set the connection params in stack</span>
<a name="l00104"></a>00104         err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga28e0062141d77d7b2272fc3a6b6e17c5" title="Set GAP Peripheral Preferred Connection Parameters.">ble_gap_ppcp_set</a>(&amp;s_preferred_conn_params);
<a name="l00105"></a>00105         <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00106"></a>00106         {
<a name="l00107"></a>00107             <span class="keywordflow">return</span> err_code;
<a name="l00108"></a>00108         }
<a name="l00109"></a>00109     }
<a name="l00110"></a>00110     <span class="keywordflow">else</span>
<a name="l00111"></a>00111     {
<a name="l00112"></a>00112         <span class="comment">// Fetch the connection params from stack</span>
<a name="l00113"></a>00113         err_code = <a class="code" href="group___b_l_e___g_a_p.html#gafece35b7f8a4abcf297c18f1e947be1a" title="Get GAP Peripheral Preferred Connection Parameters.">ble_gap_ppcp_get</a>(&amp;s_preferred_conn_params);
<a name="l00114"></a>00114         <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00115"></a>00115         {
<a name="l00116"></a>00116             <span class="keywordflow">return</span> err_code;
<a name="l00117"></a>00117         }
<a name="l00118"></a>00118     }
<a name="l00119"></a>00119 
<a name="l00120"></a>00120     <a class="code" href="group__ble__sdk__app__hrs__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a>  = <a class="code" href="group___b_l_e___c_o_n_n___h_a_n_d_l_e_s.html#gacf227b9b101dbcf08eccbbaba54e48f5">BLE_CONN_HANDLE_INVALID</a>;
<a name="l00121"></a>00121     s_update_count = 0;
<a name="l00122"></a>00122     
<a name="l00123"></a>00123     <span class="keywordflow">return</span> <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>;
<a name="l00124"></a>00124 }
<a name="l00125"></a>00125 
<a name="l00126"></a>00126 
<a name="l00127"></a><a class="code" href="group__ble__sdk__lib__conn__params.html#gaac1bde1dba73ea0cdb6fd4b242e4aa0a">00127</a> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__lib__conn__params.html#gaac1bde1dba73ea0cdb6fd4b242e4aa0a" title="Stop the Connection Parameters module.">ble_conn_params_stop</a>(<span class="keywordtype">void</span>)
<a name="l00128"></a>00128 {
<a name="l00129"></a>00129     <a class="code" href="group__app__timer.html#ga4112ddbc75deb5c4d5db7c8afb1f5d8a" title="Stops the specified timer.">app_timer_stop</a>(APP_TIMER_CONN_PARAMS);
<a name="l00130"></a>00130 }
<a name="l00131"></a>00131 
<a name="l00132"></a>00132 
<a name="l00133"></a>00133 <span class="keyword">static</span> <span class="keywordtype">void</span> conn_params_negotiation(<span class="keywordtype">void</span>)
<a name="l00134"></a>00134 {
<a name="l00135"></a>00135     <span class="comment">// Start negotiation if the received connection parameters are not acceptable</span>
<a name="l00136"></a>00136     <span class="keywordflow">if</span> (!is_conn_params_ok(&amp;s_current_conn_params))
<a name="l00137"></a>00137     {
<a name="l00138"></a>00138         uint32_t err_code;
<a name="l00139"></a>00139 
<a name="l00140"></a>00140         <span class="keywordflow">if</span> (s_update_count == 0)
<a name="l00141"></a>00141         {
<a name="l00142"></a>00142             <span class="comment">// First connection parameter update</span>
<a name="l00143"></a>00143             err_code = <a class="code" href="group__app__timer.html#ga54651d3dc5266bd7541b80918527b060" title="Starts a timer.">app_timer_start</a>(APP_TIMER_CONN_PARAMS,
<a name="l00144"></a>00144                                        update_timeout_handler,
<a name="l00145"></a>00145                                        s_conn_params_config.<a class="code" href="structble__conn__params__init__t.html#a915702f42f9a0316745403644d385f22">first_conn_params_update_delay</a>,
<a name="l00146"></a>00146                                        APP_TIMER_MODE_SINGLE_SHOT,
<a name="l00147"></a>00147                                        <a class="code" href="group__app__timer.html#ga02ba0b12340bf53b472283b752257f06">APP_TIMER_LOWEST_PRI</a>);
<a name="l00148"></a>00148         }
<a name="l00149"></a>00149         <span class="keywordflow">else</span>
<a name="l00150"></a>00150         {
<a name="l00151"></a>00151             err_code = <a class="code" href="group__app__timer.html#ga54651d3dc5266bd7541b80918527b060" title="Starts a timer.">app_timer_start</a>(APP_TIMER_CONN_PARAMS,
<a name="l00152"></a>00152                                        update_timeout_handler,
<a name="l00153"></a>00153                                        s_conn_params_config.<a class="code" href="structble__conn__params__init__t.html#a9bcd0621fbb5f4554f1fafd0b15dc61b">next_conn_params_update_delay</a>,
<a name="l00154"></a>00154                                        APP_TIMER_MODE_SINGLE_SHOT,
<a name="l00155"></a>00155                                        <a class="code" href="group__app__timer.html#ga02ba0b12340bf53b472283b752257f06">APP_TIMER_LOWEST_PRI</a>);
<a name="l00156"></a>00156         }
<a name="l00157"></a>00157 
<a name="l00158"></a>00158         <span class="keywordflow">if</span> ((err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>) &amp;&amp; (s_conn_params_config.<a class="code" href="structble__conn__params__init__t.html#a893a7b5845beb42d9e5b650fd012f7f1">error_handler</a> != NULL))
<a name="l00159"></a>00159         {
<a name="l00160"></a>00160             s_conn_params_config.<a class="code" href="structble__conn__params__init__t.html#a893a7b5845beb42d9e5b650fd012f7f1">error_handler</a>(err_code);
<a name="l00161"></a>00161         }
<a name="l00162"></a>00162     }
<a name="l00163"></a>00163 }
<a name="l00164"></a>00164 
<a name="l00165"></a>00165 
<a name="l00166"></a>00166 <span class="keyword">static</span> <span class="keywordtype">void</span> on_connect(<a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00167"></a>00167 {
<a name="l00168"></a>00168     <span class="comment">// Save connection parameters</span>
<a name="l00169"></a>00169     <a class="code" href="group__ble__sdk__app__hrs__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a>         = p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a91857ca158f0c4e43f610068772c7d3d">gatts_evt</a>.<a class="code" href="structble__gatts__evt__t.html#a0d5ffe38d68e48d81e61fc6a4999ae68">conn_handle</a>;
<a name="l00170"></a>00170     s_current_conn_params = p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a2fd98f8868b9aea30d35bf71d41d646a">gap_evt</a>.params.<a class="code" href="structble__gap__evt__t.html#a9864b5931270a6958035ebdcf82076f4">connected</a>.<a class="code" href="structble__gap__evt__connected__t.html#a8dfa0c1911f7e201f485d15701d3de40">conn_params</a>;
<a name="l00171"></a>00171     s_update_count        = 0;  <span class="comment">// Connection parameter negotiation should re-start every connection</span>
<a name="l00172"></a>00172     
<a name="l00173"></a>00173     <span class="comment">// Check if we shall handle negotiation on connect</span>
<a name="l00174"></a>00174     <span class="keywordflow">if</span> (s_conn_params_config.<a class="code" href="structble__conn__params__init__t.html#a6f0b0ef22161b61ba5cc0a7fd3ddedd9">start_on_notify_cccd_handle</a> == <a class="code" href="group___b_l_e___g_a_t_t_s.html#gaa16a29908fc63343706f56913be51ec1" title="Invalid Attribute Handle.">BLE_GATTS_HANDLE_INVALID</a>)
<a name="l00175"></a>00175     {
<a name="l00176"></a>00176         conn_params_negotiation();
<a name="l00177"></a>00177     }
<a name="l00178"></a>00178 }
<a name="l00179"></a>00179 
<a name="l00180"></a>00180 
<a name="l00181"></a>00181 <span class="keyword">static</span> <span class="keywordtype">void</span> on_disconnect(<a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00182"></a>00182 {
<a name="l00183"></a>00183     <a class="code" href="group__ble__sdk__app__hrs__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a> = <a class="code" href="group___b_l_e___c_o_n_n___h_a_n_d_l_e_s.html#gacf227b9b101dbcf08eccbbaba54e48f5">BLE_CONN_HANDLE_INVALID</a>;
<a name="l00184"></a>00184 
<a name="l00185"></a>00185     <span class="comment">// Stop timer if running</span>
<a name="l00186"></a>00186     s_update_count = 0; <span class="comment">// Connection parameters updates should happen during every connection</span>
<a name="l00187"></a>00187     <a class="code" href="group__app__timer.html#ga4112ddbc75deb5c4d5db7c8afb1f5d8a" title="Stops the specified timer.">app_timer_stop</a>(APP_TIMER_CONN_PARAMS);
<a name="l00188"></a>00188 }
<a name="l00189"></a>00189 
<a name="l00190"></a>00190 
<a name="l00191"></a>00191 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__pwr__mgmt__main.html#ga70525a816fec301fa4c9d564831c440b" title="Funtion that evaluates the value written in CCCD.">on_write</a>(<a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00192"></a>00192 {
<a name="l00193"></a>00193     <a class="code" href="structble__gatts__evt__write__t.html" title="Event structure for BLE_GATTS_EVT_WRITE.">ble_gatts_evt_write_t</a> * p_evt_write = &amp;p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a91857ca158f0c4e43f610068772c7d3d">gatts_evt</a>.params.<a class="code" href="structble__gatts__evt__t.html#a682c515271ef8a1b93b7643a1023e8b8">write</a>;
<a name="l00194"></a>00194 
<a name="l00195"></a>00195     <span class="comment">// Check if this the correct CCCD</span>
<a name="l00196"></a>00196     <span class="keywordflow">if</span> (
<a name="l00197"></a>00197         (p_evt_write-&gt;<a class="code" href="structble__gatts__evt__write__t.html#af242d6e3b6108ea75e1eb236e94c8240">handle</a> == s_conn_params_config.<a class="code" href="structble__conn__params__init__t.html#a6f0b0ef22161b61ba5cc0a7fd3ddedd9">start_on_notify_cccd_handle</a>)
<a name="l00198"></a>00198         &amp;&amp;
<a name="l00199"></a>00199         (p_evt_write-&gt;<a class="code" href="structble__gatts__evt__write__t.html#a8aed22e2c7b283705ec82e0120515618">len</a> == 2)
<a name="l00200"></a>00200     )
<a name="l00201"></a>00201     {
<a name="l00202"></a>00202         <span class="comment">// Check if this is a &#39;start notification&#39;</span>
<a name="l00203"></a>00203         <span class="keywordflow">if</span> (<a class="code" href="group__ble__sdk__srv__common.html#ga11fd3cc1b15d4bec4accc37618305ccb" title="Inline function for decoding a CCCD value, and then testing if notification is enabled.">ble_srv_is_notification_enabled</a>(p_evt_write-&gt;<a class="code" href="structble__gatts__evt__write__t.html#aa86e1085c6a16f60258f29c9d5fc2144">data</a>))
<a name="l00204"></a>00204         {
<a name="l00205"></a>00205             <span class="comment">// Do connection parameter negotiation if necessary</span>
<a name="l00206"></a>00206             conn_params_negotiation();
<a name="l00207"></a>00207         }
<a name="l00208"></a>00208         <span class="keywordflow">else</span>
<a name="l00209"></a>00209         {
<a name="l00210"></a>00210             <span class="comment">// Stop timer if running</span>
<a name="l00211"></a>00211             <a class="code" href="group__app__timer.html#ga4112ddbc75deb5c4d5db7c8afb1f5d8a" title="Stops the specified timer.">app_timer_stop</a>(APP_TIMER_CONN_PARAMS);
<a name="l00212"></a>00212         }
<a name="l00213"></a>00213     }
<a name="l00214"></a>00214 }
<a name="l00215"></a>00215 
<a name="l00216"></a>00216 
<a name="l00217"></a>00217 <span class="keyword">static</span> <span class="keywordtype">void</span> on_conn_params_update(<a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00218"></a>00218 {
<a name="l00219"></a>00219     <span class="comment">// Copy the parameters</span>
<a name="l00220"></a>00220     s_current_conn_params = p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a2fd98f8868b9aea30d35bf71d41d646a">gap_evt</a>.params.<a class="code" href="structble__gap__evt__t.html#a1a90205e27085e2a3c7e82502c8ae008">conn_param_update</a>.<a class="code" href="structble__gap__evt__conn__param__update__t.html#a8dfa0c1911f7e201f485d15701d3de40">conn_params</a>;
<a name="l00221"></a>00221 
<a name="l00222"></a>00222     conn_params_negotiation();
<a name="l00223"></a>00223 }
<a name="l00224"></a>00224 
<a name="l00225"></a>00225 
<a name="l00226"></a><a class="code" href="group__ble__sdk__lib__conn__params.html#gadef0873bee110db3da8b77f801177871">00226</a> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__lib__conn__params.html#gadef0873bee110db3da8b77f801177871" title="BLE stack event handler.">ble_conn_params_on_ble_evt</a>(<a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00227"></a>00227 {
<a name="l00228"></a>00228     <span class="keywordflow">switch</span> (p_ble_evt-&gt;<a class="code" href="structble__evt__t.html#a50f33abba5627a26728ba30fffd9880a">header</a>.<a class="code" href="structble__evt__hdr__t.html#a826314e7ea25d4267621899efe6859f9">evt_id</a>)
<a name="l00229"></a>00229     {
<a name="l00230"></a>00230         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035daa0b4789724d202a13a5e7eab85c52957">BLE_GAP_EVT_CONNECTED</a>:
<a name="l00231"></a>00231             on_connect(p_ble_evt);
<a name="l00232"></a>00232             <span class="keywordflow">break</span>;
<a name="l00233"></a>00233             
<a name="l00234"></a>00234         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da057001bbd6ea9e615f19ef93cc0831ee">BLE_GAP_EVT_DISCONNECTED</a>:
<a name="l00235"></a>00235             on_disconnect(p_ble_evt);
<a name="l00236"></a>00236             <span class="keywordflow">break</span>;
<a name="l00237"></a>00237             
<a name="l00238"></a>00238         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_t_t_s.html#gga80155586fa275b28773c9b203f52cabaaa68b7764f5264ff092d2ad17851355ed">BLE_GATTS_EVT_WRITE</a>:
<a name="l00239"></a>00239             <a class="code" href="group__ble__sdk__app__pwr__mgmt__main.html#ga70525a816fec301fa4c9d564831c440b" title="Funtion that evaluates the value written in CCCD.">on_write</a>(p_ble_evt);
<a name="l00240"></a>00240             <span class="keywordflow">break</span>;
<a name="l00241"></a>00241             
<a name="l00242"></a>00242         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da9117fcf7efad580886dfad72e5d7cce7">BLE_GAP_EVT_CONN_PARAM_UPDATE</a>:
<a name="l00243"></a>00243             on_conn_params_update(p_ble_evt);
<a name="l00244"></a>00244             <span class="keywordflow">break</span>;
<a name="l00245"></a>00245             
<a name="l00246"></a>00246         <span class="keywordflow">default</span>:
<a name="l00247"></a>00247             <span class="keywordflow">break</span>;
<a name="l00248"></a>00248     }
<a name="l00249"></a>00249 }
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>ble_conn_params.c</b>      </li>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
      Copyright &copy 2006-2011 <a href="http://www.nordicsemi.no" style="text-decoration:none">Nordic Semiconductor</a>.
      All Rights Reserved.
      <a href="disclaimer.html">Disclaimer</a>
    </li>
   </ul>
 </div>


</body>
</html>
